#include "addcontactform.h"
#include "ui_addcontactform.h"
#include "addcontactitem.h"

AddContactForm::AddContactForm(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::AddContactForm)
{
    ui->setupUi(this);
    this->setWindowTitle(" ");

    //隐藏两张界面，同时只显示一张QListWidget界面
    ui->friend_contact_list->setVisible(false);
    ui->group_contact_list->setVisible(false);

    this->setWindowModality(Qt::ApplicationModal);

    //搜索框逻辑
    QPixmap search_pix(":/images/search.png");
    search_pix.scaled(ui->label->size(), Qt::KeepAspectRatio);
    ui->label->setScaledContents(true);
    ui->label->setPixmap(search_pix);
    ui->lineEdit_addcontact->setPlaceholderText("搜索");
    ui->addcontact_btn->setVisible(false);//隐藏撤销按钮，当搜索框获取焦点时显示
    //当搜索框获得焦点时候的信号连接
    connect(ui->lineEdit_addcontact,&SearchLineEdit::hasfocus,this,&AddContactForm::showBtn);
    //当搜索框失去焦点时候的信号连接
    connect(ui->lineEdit_addcontact,&SearchLineEdit::losefocus,this,&AddContactForm::hideBtn);

    QVector<QString> test = {"sfjnj","sjbsbvwiuenwdeqijwoijwd","收件人VB捏女我弄姐姐的问卷调查可能就",
                              "wkjerhkjeflaejrvpkasjdvasnddad","上课的局部偶尔金佛继续就没人非叫我金额快点开",
                              "srngfmme","sefwef"," ",
                              "edwef","wef","qwdqwdqwd",
                              "edwfejfhwefoiaej","ef","wefwefdqwed",
                             "省发改委辜负我后","qwedqljwhjdqw","ewfwefwjefojiwedjo"};
    int a = 0;
    for(QString str : test){
        auto *addcontact_item = new AddContactItem();
        addcontact_item->SetInfo(a%2,QString::number(a),str);
        a++;
        QListWidgetItem *item = new QListWidgetItem;
        item->setSizeHint(QSize(250,70));
        ui->all_contact_list->addItem(item);
        ui->all_contact_list->setItemWidget(item,addcontact_item);

    }

    auto *addcontact_item = new AddContactItem;
    addcontact_item->SetInfo(0,"QString::number(a)","str");

    QListWidgetItem *item = new QListWidgetItem;
    item->setSizeHint(QSize(250,70));
    ui->all_contact_list->addItem(item);
    ui->all_contact_list->setItemWidget(item,addcontact_item);
}


void AddContactForm::showBtn()
{
    ui->addcontact_btn->setVisible(true);
}

void AddContactForm::hideBtn()
{
    if( ui->addcontact_btn->isVisible() && ui->lineEdit_addcontact->text().isEmpty() )
        ui->addcontact_btn->setVisible(false);
}

AddContactForm::~AddContactForm()
{
    delete ui;
}




void AddContactForm::on_addcontact_btn_clicked()
{
    ui->lineEdit_addcontact->clear();
    ui->lineEdit_addcontact->clearFocus();
    ui->addcontact_btn->setVisible(false);
}

